import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/entrance/route/routes.dart';
import 'package:search_people/page/dynamic/main/index.dart';
import 'package:search_people/page/dynamic/subs/dynamic_leaders/cell.dart';
import 'package:search_people/page/dynamic/subs/dynamic_leaders/offcut.dart';
import 'package:search_people/page/home/subs/person_detail/models/person_dynamic_model.dart';
import 'package:search_people/value/topcolors.dart';

class DynamicCardWidget extends StatelessWidget {
  DynamicCardWidget({
    Key? key,
    required this.md,
  }) : super(key: key);
  final DynamicCardModel md;
  final controller = Get.find<DynamicController>();
  bool hasMore = true;
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(12.r, 10.r, 12.r, 0),
      padding: EdgeInsets.symmetric(horizontal: 10.r),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border.all(color: TopColors.bg),
        borderRadius: BorderRadius.circular(3.r),
      ),
      child: Column(
        children: [
          MoreDataHeader(
            title: md.title,
            onTap: () {
              Get.toNamed(RouterPath.dynamic_all,
                  arguments: {'title': md.title});
            },
          ),
          Column(
            children: getList().map((e) => DynamicLeaderCell()).toList(),
          ),
          !hasMore
              ? const SizedBox()
              : MoreDataFooter(
                  isExpend: md.isExpend,
                  onTap: () {
                    md.isExpend = !md.isExpend;
                    controller.update();
                  },
                ),
        ],
      ),
    );
  }

  List<PersonDynamicModel> getList() {
    if (md.list == null) {
      return [];
    }
    if (md.list!.length < 3) {
      hasMore = false;
      return md.list!;
    }
    return md.isExpend ? md.list! : md.list!.sublist(0, 3);
  }
}
